package com.ehl.capture.db;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Properties;
import java.util.Set;
import org.apache.log4j.Logger;

public class Config
{
    private static Logger logger = Logger.getLogger(Config.class);
    private static Properties prop = null;

    private static synchronized Properties getProp() {
        String filePath = System.getProperty("user.dir") + "/conf/conf.properties";
        if (prop == null) {
            logger.info("config init....");
            prop = new Properties();
            try
            {
                BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(filePath), "UTF-8"));
                prop.load(in);
                in.close();
                logger.info("config init success!!!");
            } catch (Exception e) {
                logger.info("config init error!!!");
                e.printStackTrace();
            }
        }
        return prop;
    }

    public static String getValue(String key) {
        return getProp().getProperty(key);
    }

    public static List<String> getPrefixedPropertyValue(String prefixKey) {
        List values = new ArrayList();
        Properties props = getProp();
        for (Iterator localIterator = props.keySet().iterator(); localIterator.hasNext(); ) { Object keyObj = localIterator.next();
            if ((keyObj != null) && (((String)keyObj).startsWith(prefixKey))) {
                values.add(props.getProperty((String)keyObj));
            } }

        return values;
    }
}